﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Share_PostingDetailControl : System.Web.UI.UserControl
{
    PostingDAO postDAO = new PostingDAO();
    SaleDAO saleDAO = new SaleDAO();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        int postID = int.Parse(Request["PostingID"]);    
        DataSet ds = postDAO.GetPostingInfoByPostingID(postID);
        IList<PostingInfo> list = new List<PostingInfo>();
        //list.Add(p);
        if (ds.Tables.Count>0)
        {
            dtlPostingDetails.DataSource = ds;
            dtlPostingDetails.DataBind();
            foreach (DataListItem item in dtlPostingDetails.Items)
            {
                ((Label)item.FindControl("lb_AverageMarks")).Text = postDAO.Average(postID);
            }
            loadgrv_Mark(postID);
        }
        LoadMark(false);
        SetRoleView();
        
    }
    
    protected void ClosePopup(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.ToString());
    }

    protected void HideMark(object sender, EventArgs e)
    {
        LoadMark(false);
    }
    protected void  ViewMarkDetail(object sender, EventArgs e)
    {
        LoadMark(true);
    }
    public void LoadMark(bool f)
    {

        foreach (DataListItem item in dtlPostingDetails.Items)
        {
            ((Panel)item.FindControl("pn_MarkDetail")).Visible = f;
        }
    }
   
    protected void dtlPostingDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("http://google.com");
    }
    public void loadgrv_Mark(int postID)
    {
        foreach(DataListItem item in dtlPostingDetails.Items)
        {
            GridView grv = (GridView)item.FindControl("grv_MarkDetail");
            grv.DataSource = postDAO.getMarkByPostingID(postID);
            grv.DataBind();
        }
    }
   
    protected void btn_Update_Click(object sender, EventArgs e)
    {         
        Response.Redirect("~/Admin/UpdatePosting.aspx?PostingID="+ Request["PostingID"].ToString());
    }
    protected void btnHide_Click(object sender, EventArgs e)
    {
        string[] temp = Request.Url.ToString().Split('?');
        Response.Redirect(temp[0]);
    }
    public void SetRoleView()
    {
        if (Session["roleID"] != null)
        {
            int roleID = int.Parse(Session["roleID"].ToString());
            if (roleID != 4)            
                btn_Update.Visible = false;
            
        }
    }
}